﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Churchtoolkit.Web.Shell.Presenters;
using Churchtoolkit.DataAccess.Entities;

namespace Churchtoolkit.Web
{
    public partial class ChangePassword : Churchtoolkit.Utils.ErrorProvider.Page<ChangePasswordPresenter>
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                vldOldPassword.Replace("[Field]", "Old Password");
                PasswordRequiredValidator.Replace("[Field]", "New Password");
                ConfirmValidator.Replace("[Field]", "Confirm Password");
                PasswordCompareValidator.Replace("[Field]", "Confirm Password");
            }
        }


        protected void oldPassword_ServerValidate(object source, ServerValidateEventArgs args)
        {
            args.IsValid = this.Presenter.IsOldPasswordValid(this.txtOldPassword.Text);
        }


        protected void ChangeOldPassword(object sender, EventArgs e)
        {
            if (this.IsValid)
            {
                SaveNewPassword();
            }
        }

        void SaveNewPassword()
        {
            Presenter.ChangeToNewPassword(txtNewPassword.Text);
        }
    }
}